﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Douban.Modules.Info.ViewModels;
using System.Windows.Threading;
using Microsoft.Practices.Composite;

namespace Douban.Modules.Info.Views
{
    /// <summary>
    /// Interaction logic for UserInfoView.xaml
    /// </summary>
    public partial class UserInfoView : IUserInfoView, IActiveAware
    {
        private bool _isActive;

        public UserInfoView()
        {
            InitializeComponent();
        }

        public IUserInfoViewModel Context
        {
            get { return DataContext as IUserInfoViewModel; }
            set
            {
                DataContext = value;
            }
        }

        #region IActiveAware Members

        public bool IsActive
        {
            get { return _isActive; }
            set
            {
                if (_isActive != value)
                {
                    _isActive = value;
                    OnIsActiveChanged(this, EventArgs.Empty);
                }
            }
        }

        event EventHandler IActiveAware.IsActiveChanged
        {
            add { throw new NotImplementedException(); }
            remove { throw new NotImplementedException(); }
        }

        #endregion

        public event RoutedEventHandler IsActiveChanged
        {
            add { AddHandler(IsActiveChangedEvent, value); }
            remove { RemoveHandler(IsActiveChangedEvent, value); }
        }

        public static readonly RoutedEvent IsActiveChangedEvent =
            EventManager.RegisterRoutedEvent("IsActiveChanged", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(UserInfoView));

        private void OnIsActiveChanged(object sender, EventArgs e)
        {
            RaiseEvent(new RoutedEventArgs(IsActiveChangedEvent, this));
        }
    }
}
